/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlykho;

import java.awt.Color;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;

/**
 *
 * @author Admin
 */
public class FormMain extends javax.swing.JFrame {

    static String User;

    /**
     * Creates new form FormMain
     */
    public FormMain() {
        initComponents();
        p4.setVisible(false);
        JOptionPane.showMessageDialog(this, "Login successfully");
        phanghoa.removeAll();
        QuanLyHangHoa hh = new QuanLyHangHoa();
        phanghoa.add(hh);
        hh.setSize(800, 500);
        hh.setLocation(0, 0);
        hh.setVisible(true);
        phanghoa.updateUI();
        phanghoa.setEnabled(true);
        
        pnv.removeAll();
        QuanLyNV nv = new QuanLyNV();
        pnv.add(nv);
        nv.setSize(800, 500);
        nv.setLocation(0, 0);
        nv.setVisible(true);
        pnv.updateUI();
        pnv.setEnabled(true);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        p1 = new javax.swing.JPanel();
        AddUser = new javax.swing.JButton();
        LogOut = new javax.swing.JButton();
        p4 = new javax.swing.JPanel();
        ViewDeleteUser = new javax.swing.JButton();
        UpdateUser = new javax.swing.JButton();
        ChangePassword = new javax.swing.JButton();
        p2 = new javax.swing.JPanel();
        p5 = new javax.swing.JPanel();
        HDNhap = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        p3 = new javax.swing.JPanel();
        HDXuat = new javax.swing.JButton();
        p6 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        phanghoa = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        pnv = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        p7 = new javax.swing.JPanel();

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTabbedPane1.setPreferredSize(new java.awt.Dimension(500, 600));
        jTabbedPane1.setRequestFocusEnabled(false);

        p1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        AddUser.setText("Add User");
        AddUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddUserActionPerformed(evt);
            }
        });

        LogOut.setText("Logout");
        LogOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LogOutActionPerformed(evt);
            }
        });

        p4.setPreferredSize(new java.awt.Dimension(300, 200));

        javax.swing.GroupLayout p4Layout = new javax.swing.GroupLayout(p4);
        p4.setLayout(p4Layout);
        p4Layout.setHorizontalGroup(
            p4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 441, Short.MAX_VALUE)
        );
        p4Layout.setVerticalGroup(
            p4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 381, Short.MAX_VALUE)
        );

        ViewDeleteUser.setText("View And Delete User");
        ViewDeleteUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ViewDeleteUserActionPerformed(evt);
            }
        });

        UpdateUser.setText("Update User");
        UpdateUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UpdateUserActionPerformed(evt);
            }
        });

        ChangePassword.setText("Change Password");
        ChangePassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ChangePasswordActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p1Layout = new javax.swing.GroupLayout(p1);
        p1.setLayout(p1Layout);
        p1Layout.setHorizontalGroup(
            p1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(LogOut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(UpdateUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ChangePassword, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ViewDeleteUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(AddUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(47, 47, 47)
                .addComponent(p4, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(108, Short.MAX_VALUE))
        );
        p1Layout.setVerticalGroup(
            p1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p1Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(p1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(p4, javax.swing.GroupLayout.PREFERRED_SIZE, 381, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(p1Layout.createSequentialGroup()
                        .addComponent(AddUser, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ViewDeleteUser, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(UpdateUser, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ChangePassword, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(LogOut, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(472, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("User Management", p1);

        p2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        p5.setPreferredSize(new java.awt.Dimension(300, 200));

        javax.swing.GroupLayout p5Layout = new javax.swing.GroupLayout(p5);
        p5.setLayout(p5Layout);
        p5Layout.setHorizontalGroup(
            p5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 731, Short.MAX_VALUE)
        );
        p5Layout.setVerticalGroup(
            p5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 566, Short.MAX_VALUE)
        );

        HDNhap.setText("Tạo Phiếu Nhập");
        HDNhap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HDNhapActionPerformed(evt);
            }
        });

        jButton1.setText("View và Update Phiếu Nhập");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p2Layout = new javax.swing.GroupLayout(p2);
        p2.setLayout(p2Layout);
        p2Layout.setHorizontalGroup(
            p2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p2Layout.createSequentialGroup()
                .addGroup(p2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(p2Layout.createSequentialGroup()
                        .addComponent(HDNhap, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1)
                        .addGap(0, 397, Short.MAX_VALUE))
                    .addComponent(p5, javax.swing.GroupLayout.DEFAULT_SIZE, 731, Short.MAX_VALUE))
                .addContainerGap())
        );
        p2Layout.setVerticalGroup(
            p2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p2Layout.createSequentialGroup()
                .addGroup(p2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(HDNhap, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(p5, javax.swing.GroupLayout.PREFERRED_SIZE, 566, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(266, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Nhập Hàng", p2);

        p3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        HDXuat.setText("Tạo Phiếu Xuất");
        HDXuat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HDXuatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p6Layout = new javax.swing.GroupLayout(p6);
        p6.setLayout(p6Layout);
        p6Layout.setHorizontalGroup(
            p6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        p6Layout.setVerticalGroup(
            p6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 835, Short.MAX_VALUE)
        );

        jButton2.setText("View và Update Phiếu Xuất");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p3Layout = new javax.swing.GroupLayout(p3);
        p3.setLayout(p3Layout);
        p3Layout.setHorizontalGroup(
            p3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(p6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(p3Layout.createSequentialGroup()
                        .addComponent(HDXuat, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 322, Short.MAX_VALUE)))
                .addContainerGap())
        );
        p3Layout.setVerticalGroup(
            p3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p3Layout.createSequentialGroup()
                .addGroup(p3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(HDXuat, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(p6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Bán Hàng", p3);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout phanghoaLayout = new javax.swing.GroupLayout(phanghoa);
        phanghoa.setLayout(phanghoaLayout);
        phanghoaLayout.setHorizontalGroup(
            phanghoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 639, Short.MAX_VALUE)
        );
        phanghoaLayout.setVerticalGroup(
            phanghoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 438, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(phanghoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(92, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(phanghoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(435, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Hàng Hóa", jPanel1);

        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout pnvLayout = new javax.swing.GroupLayout(pnv);
        pnv.setLayout(pnvLayout);
        pnvLayout.setHorizontalGroup(
            pnvLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 727, Short.MAX_VALUE)
        );
        pnvLayout.setVerticalGroup(
            pnvLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 448, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addComponent(pnv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(421, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Nhân Viên", jPanel4);

        jPanel7.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jButton3.setText("Theo Mã Hàng");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p7Layout = new javax.swing.GroupLayout(p7);
        p7.setLayout(p7Layout);
        p7Layout.setHorizontalGroup(
            p7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        p7Layout.setVerticalGroup(
            p7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 564, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 609, Short.MAX_VALUE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(p7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(p7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(277, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Thống Kê", jPanel7);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(60, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 750, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 916, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void AddUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddUserActionPerformed
        try {
            // TODO add your handling code here:
            Ketnoi a = new Ketnoi();
            Connection con;
            con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
            pst.setString(1, User);
            ResultSet rs = pst.executeQuery();
            int ut = 0;
            while (rs.next()) {
                ut = rs.getInt(3);
            }
            if (ut == 1) {

                p4.removeAll();
                AddUser b = new AddUser();
                b.setSize(400, 250);
                b.setLocation(0, 0);
                b.setVisible(true);
                b.setBorder(BorderFactory.createLineBorder(Color.blue));

                p4.add(b);
                p4.updateUI();
                p4.setVisible(true);
            } else {
                p4.setVisible(false);
                JOptionPane.showMessageDialog(this, "Bạn không được cấp quyền.");
            }
        } catch (SQLException ex) {
            Logger.getLogger(FormMain.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_AddUserActionPerformed

    private void LogOutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LogOutActionPerformed
        // TODO add your handling code here:
        this.dispose();
        String[] args = null;
        FormLogin.main(args);
    }//GEN-LAST:event_LogOutActionPerformed

    private void ViewDeleteUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ViewDeleteUserActionPerformed
        // TODO add your handling code here:
        try {
            Ketnoi a = new Ketnoi();
            Connection con;
            con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
            pst.setString(1, User);
            ResultSet rs = pst.executeQuery();
            int ut = 0;
            while (rs.next()) {
                ut = rs.getInt(3);
            }
            if (ut == 1) {

                p4.removeAll();;
                ViewDeleteUser b = new ViewDeleteUser();
                b.setSize(400, 200);
                b.setLocation(0, 0);
                b.setVisible(true);
                b.setBorder(BorderFactory.createLineBorder(Color.BLUE));
                p4.add(b);
                p4.updateUI();
                p4.setVisible(true);
            } else {
                p4.setVisible(false);
                JOptionPane.showMessageDialog(this, "Bạn không được cấp quyền.");
            }
        } catch (SQLException ex) {
            Logger.getLogger(FormMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_ViewDeleteUserActionPerformed

    private void UpdateUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UpdateUserActionPerformed
        // TODO add your handling code here:
        try {
            Ketnoi a = new Ketnoi();
            Connection con;
            con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
            pst.setString(1, User);
            ResultSet rs = pst.executeQuery();
            int ut = 0;
            while (rs.next()) {
                ut = rs.getInt(3);
            }
            if (ut == 1) {

                p4.removeAll();;
                UpdateUser b = new UpdateUser();
                b.setSize(400, 200);
                b.setLocation(0, 0);
                b.setVisible(true);
                b.setBorder(BorderFactory.createLineBorder(Color.BLUE));
                p4.add(b);
                p4.updateUI();
                p4.setVisible(true);
            } else {
                p4.setVisible(false);
                JOptionPane.showMessageDialog(this, "Bạn không được cấp quyền.");
            }
        } catch (SQLException ex) {
            Logger.getLogger(FormMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_UpdateUserActionPerformed

    private void ChangePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChangePasswordActionPerformed
        // TODO add your handling code here:
        try {
            Ketnoi a = new Ketnoi();
            Connection con;
            con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
            pst.setString(1, User);
            ResultSet rs = pst.executeQuery();


            p4.removeAll();;
            ChangePassword b = new ChangePassword(User);
            b.setSize(400, 200);
            b.setLocation(0, 0);
            b.setVisible(true);
            b.setBorder(BorderFactory.createLineBorder(Color.BLUE));
            p4.add(b);
            p4.updateUI();
            p4.setVisible(true);

        } catch (SQLException ex) {
            Logger.getLogger(FormMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_ChangePasswordActionPerformed

    private void HDNhapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HDNhapActionPerformed
        // TODO add your handling code here:
         try {
            Ketnoi a = new Ketnoi();
            Connection con;
            con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
            pst.setString(1, User);
            ResultSet rs = pst.executeQuery();
            int ut = 0;
            while (rs.next()) {
                ut = rs.getInt(3);
            }
            if (ut == 1 || ut == 2) {

                p5.removeAll();;
                HDNhap b = new HDNhap(User);
                b.setSize(650, 550);
                b.setLocation(0, 0);
                b.setVisible(true);
                b.setBorder(BorderFactory.createLineBorder(Color.BLUE));

                p5.add(b);
                p5.updateUI();
                p5.setVisible(true);
            } else {
                p5.setVisible(false);
                JOptionPane.showMessageDialog(this, "Bạn không được cấp quyền.");
            }
        } catch (SQLException ex) {
            Logger.getLogger(FormMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_HDNhapActionPerformed

    private void HDXuatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HDXuatActionPerformed
        // TODO add your handling code here:
        try {
            Ketnoi a = new Ketnoi();
            Connection con;
            con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
            pst.setString(1, User);
            ResultSet rs = pst.executeQuery();
            int ut = 0;
            while (rs.next()) {
                ut = rs.getInt(3);
            }
            if (ut == 1 || ut == 2) {

                p6.removeAll();;
                HDXuat b = new HDXuat(User);
                b.setSize(670, 700);
                b.setLocation(0, 0);
                b.setVisible(true);
                b.setBorder(BorderFactory.createLineBorder(Color.BLUE));

                p6.add(b);
                p6.updateUI();
                p6.setVisible(true);
            } else {
                p6.setVisible(false);
                JOptionPane.showMessageDialog(this, "Bạn không được cấp quyền.");
            }
        } catch (SQLException ex) {
            Logger.getLogger(FormMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_HDXuatActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        try {
            Ketnoi a = new Ketnoi();
            Connection con;
            con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
            pst.setString(1, User);
            ResultSet rs = pst.executeQuery();
            int ut = 0;
            while (rs.next()) {
                ut = rs.getInt(3);
            }
            if (ut == 1 || ut == 2) {

                p5.removeAll();;
                UdHDNhap b = new UdHDNhap(User);
                b.setSize(650, 430);
                b.setLocation(0, 0);
                b.setVisible(true);
                b.setBorder(BorderFactory.createLineBorder(Color.BLUE));

                p5.add(b);
                p5.updateUI();
                p5.setVisible(true);
            } else {
                p5.setVisible(false);
                JOptionPane.showMessageDialog(this, "Bạn không được cấp quyền.");
            }
        } catch (SQLException ex) {
            Logger.getLogger(FormMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
                try {
            Ketnoi a = new Ketnoi();
            Connection con;
            con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
            pst.setString(1, User);
            ResultSet rs = pst.executeQuery();
            int ut = 0;
            while (rs.next()) {
                ut = rs.getInt(3);
            }
            if (ut == 1 || ut == 2) {

                p6.removeAll();;
                UdHDXuat b = new UdHDXuat(User);
                b.setSize(650, 550);
                b.setLocation(0, 0);
                b.setVisible(true);
                b.setBorder(BorderFactory.createLineBorder(Color.BLUE));

                p6.add(b);
                p6.updateUI();
                p6.setVisible(true);
            } else {
                p6.setVisible(false);
                JOptionPane.showMessageDialog(this, "Bạn không được cấp quyền.");
            }
        } catch (SQLException ex) {
            Logger.getLogger(FormMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try {
            // TODO add your handling code here:
                Ketnoi a = new Ketnoi();
                Connection con;
                con = a.connect();
                PreparedStatement pst = con.prepareCall("Select * from dangnhap where [User] = ?");
                pst.setString(1, User);
                ResultSet rs = pst.executeQuery();
                int ut = 0;
                while (rs.next()) {
                    ut = rs.getInt(3);
                }
                if (ut == 1 || ut == 2) {

                    p7.removeAll();
                     TKHangHoa b = new TKHangHoa();
                    b.setSize(750, 550);
                    b.setLocation(0, 0);
                    b.setVisible(true);

                    p7.add(b);
                    p7.updateUI();
                    p7.setVisible(true);
                } else {
                    p7.setVisible(false);
                    JOptionPane.showMessageDialog(this, "Bạn không được cấp quyền.");
                }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
            
    }//GEN-LAST:event_jButton3ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        User = args[0];
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddUser;
    private javax.swing.JButton ChangePassword;
    private javax.swing.JButton HDNhap;
    private javax.swing.JButton HDXuat;
    private javax.swing.JButton LogOut;
    private javax.swing.JButton UpdateUser;
    private javax.swing.JButton ViewDeleteUser;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel p1;
    private javax.swing.JPanel p2;
    private javax.swing.JPanel p3;
    private javax.swing.JPanel p4;
    private javax.swing.JPanel p5;
    private javax.swing.JPanel p6;
    private javax.swing.JPanel p7;
    private javax.swing.JPanel phanghoa;
    private javax.swing.JPanel pnv;
    // End of variables declaration//GEN-END:variables
}
